package com.cike.productmanager.DBHelper;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class ActivityInfoContentHandler extends DefaultHandler {

	private static final String TAG = "XMLContentHandler";
	private List<ActivityInfo> activityInfos;
	private ActivityInfo activityInfo;
	private String preTag;
	
	
	public List<ActivityInfo> getActivityInfos()
	{
		Log.i("Info", "���¼����:"+activityInfos.size());
		return activityInfos;
	}


	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		String data=null;
		if (activityInfo!=null)
		{
			if("name".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.name=data;
			}
			else if("id".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.id=data;
			}
			else if("type".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.type=data;
			}
			
			else if("code".equals(preTag))//�ŵ����
			{
				data = new String(ch, start,length);
				activityInfo.code=data;
			}
			else if("starttime".equals(preTag))//���ʼʱ��
			{
				data = new String(ch, start,length);
				activityInfo.startTime=data;
			}
			else if("endtime".equals(preTag))//
			{
				data = new String(ch, start,length);
				activityInfo.endTime=data;
			}
			else if("level".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.level=data;
			}

			else if("content".equals(preTag))
			{
				data = new String(ch, start,length);
				if(activityInfo.content!=null&&activityInfo.content.length()>0)
				{
					activityInfo.content=activityInfo.content+data;
				}
				else
				{
					activityInfo.content=data;
				}
				
			}
			else if("state".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.state=data;
			}
			else if("remark".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.remark=data;
			}
			//������ǩ 
			else if("storename".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.storeName=data;
			}
			else if("storetype".equals(preTag))
			{
				data = new String(ch, start,length);
				activityInfo.storeType=data;
			}
			else if("showway".equals(preTag))//���з�ʽ
			{
				data = new String(ch, start,length);
				activityInfo.display=data;
			}
			else if("showNum".equals(preTag))//����
			{
				data = new String(ch, start,length);
				activityInfo.displaycount=data;
			}
			else if("actustarttime".equals(preTag))//����Ա��ʱ��
			{
				data = new String(ch, start,length);
				activityInfo.promostime=data;
			}
			else if("actuendtime".equals(preTag))//����Ա�볡ʱ��
			{
				data = new String(ch, start,length);
				activityInfo.promoetime=data;
			}
			else if("saleNum".equals(preTag))//����Ա����
			{
				data = new String(ch, start,length);
				activityInfo.promocount=data;
			}
			else if("salerstatus".equals(preTag))//����Ա״̬,�Ƿ񵽳�
			{
				data = new String(ch, start,length);
				activityInfo.promostate=data;
			}
			else if("isArrived".equals(preTag))//��Ʒ�Ƿ񵽴�
			{
				data = new String(ch, start,length);
				activityInfo.promoproductstate=data;
			}
			else if("materialArrived".equals(preTag))//�����Ƿ񵽴�
			{
				data = new String(ch, start,length);
			}
			else if("actushowway".equals(preTag))//ʵ�ʵĳ��з�ʽ
			{
				data = new String(ch, start,length);
				activityInfo.realdisplay=data;
			}
			else if("isPhotoed".equals(preTag))//�Ƿ�����
			{
				data = new String(ch, start,length);
				activityInfo.isphoto=data;
			}
			else if("imgpath".equals(preTag))//ͼƬ·��
			{
				data = new String(ch, start,length);
				activityInfo.imagePath=data;
			}else if("required".equals(preTag)) //ִ��Ҫ��
			{
			    data = new String(ch, start,length);
			    activityInfo.required=data;
			}

			
			
			//�����ӱ�ǩ��
//			<plan>
//			<name>�1</name>
//			<id>516</id>
//			<storename>ԣ���ٻ�</storename>
//			<storetype>M-SPM</storetype>
//			<showway>��ɫ����</showway>
//			<showNum>1</showNum>
//			<starttime>2012-11-21 00:00:00.0</starttime>
//			<endtime>2012-12-11 00:00:00.0</endtime>
//			<actustarttime>2012-11-21 00:00:00.0</actustarttime>
//			<actuendtime>2012-12-04 00:00:00.0</actuendtime>
//			<saleNum>1</saleNum>
//			<salerstatus>δ��/�ѽ�</salerstatus>
//			<isArrived/>
//			<materialArrived/>
//			<actushowway/>
//			<isPhotoed/>
//			<imgpath/>
//			<isPhotoed/>
//			<totalnum/>
//			<type>����</type>
//			<code>820027</code>
//			<level>һ��</level>
//			<content/>
//			<state>δִ��</state>
//			<remark/>
//			</plan>
			
			
		}
		//Log.i(TAG, "�������ݣ�"+new String(ch, start,length));
		
	}


	@Override
	public void endDocument() throws SAXException {
		super.endDocument();
		Log.i(TAG, "�ĵ��������");
	}


	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if ("plan".equals(localName)&&activityInfo!=null)
		{
			activityInfos.add(activityInfo);
			activityInfo = null;
		}
		String tag=preTag;
		preTag = null;
		Log.i(TAG, localName + "�������");
		
	}


	@Override
	public void startDocument() throws SAXException {

		activityInfos = new ArrayList<ActivityInfo>();
		Log.i(TAG, "��ʼ����...");
	}


	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		try {
			if ("plan".equals(localName)) 
			{
				activityInfo = new ActivityInfo();
//				report.setReportName(new String(attributes.getValue("reportName")));
			}

			
			preTag = localName;
			Log.i(TAG, "����Ԫ�أ�" + localName);
		} catch (Exception e)
		{
//			Util.Log(e.toString());
		}
	}
}
